package mail.impl;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import mail.base.MessageCreator;
import mail.bean.MessageVo;

public class RtfMessageCreator implements MessageCreator {

  public Message create(MessageVo vo, Session session) {
    if(vo == null) {
      return null;
    }
    Message msg = new MimeMessage(session);
    try {
      msg.setFrom(new InternetAddress(vo.getSenderAddr()));
      msg.setSubject(vo.getSubject());
      msg.setContent(vo.getContent(), "text/rtf");
    } catch (AddressException e) {
      e.printStackTrace();
      return null;
    } catch (MessagingException e) {
      e.printStackTrace();
      return null;
    }
    return msg;
  }

}
